package com.netflexitysolutions.amazonws.s3.internal.operations;

import java.util.List;

import com.amazonaws.s3.doc._2006_03_01.GetBucketLoggingStatus;
import com.amazonaws.s3.doc._2006_03_01.GetBucketLoggingStatusResponse;
import com.amazonaws.s3.doc._2006_03_01.LoggingSettings;
import com.netflexitysolutions.amazonws.s3.S3;
import com.netflexitysolutions.amazonws.s3.S3Grant;
import com.netflexitysolutions.amazonws.s3.S3LoggingSettings;
import com.netflexitysolutions.amazonws.s3.internal.utils.S3Utils;

public class GetBucketLoggingStatusOperation extends OperationExecutor<GetBucketLoggingStatus, S3LoggingSettings>{

    private String bucket;

    public GetBucketLoggingStatusOperation(S3 s3, String bucket){
        super(s3);
        this.bucket = bucket;
    }

    @Override
    protected S3LoggingSettings call(GetBucketLoggingStatus request) {
        request.setBucket(bucket);
        injectCredentials(request, "GetBucketLoggingStatus", getS3().getAccessKey(), getS3().getSecretKey());
        GetBucketLoggingStatusResponse response = getS3().getService().getBucketLoggingStatus(request);
        LoggingSettings ls = response.getGetBucketLoggingStatusResponse().getLoggingEnabled();
        List<S3Grant> acl = S3Utils.convert(ls.getTargetGrants());
        return new S3LoggingSettings(ls.getTargetBucket(), ls.getTargetPrefix(), acl);
    }
}
